package com.ruoyi.web.controller.llm;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.llm.domain.po.KnowledgeInfoPo;
import com.ruoyi.llm.domain.vo.KnowledgeInfoVo;
import com.ruoyi.llm.service.KnowledgeInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.PostConstruct;
import java.util.List;

import static com.ruoyi.common.core.page.TableSupport.PAGE_SIZE;

@Api(tags="知识库接口")
@RestController
@RequestMapping("/llm/knowledge")
public class KnowledgeInfoController  extends BaseController {

    @Autowired
    private KnowledgeInfoService klinfoService;

    @PostConstruct
    public void init(){
        System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~   KnowledgeInfoController   ~~~");
    }

    @GetMapping("/list")
    @ApiOperation(value = "所有知识库列表",response= KnowledgeInfoPo.class)
    public TableDataInfo knowledgeList(String name,Integer pageNum,Integer pageSize)
    {
        startPage();
        if(pageSize == null){
            pageSize = 10;
        }
        if(pageNum == null){
            pageNum = 1;
        }
        PageHelper.startPage(pageNum,pageSize);
        List<KnowledgeInfoPo> ls=klinfoService.listKnowledgeInfo(name);
        return getDataTable(ls);
    }

    @GetMapping("/get")
    @ApiOperation(value = "获取知识库详情",response= KnowledgeInfoPo.class)
    public AjaxResult getKnowledge(@RequestParam("docId") String docId)
    {
        KnowledgeInfoVo ls=klinfoService.getKnowledgeInfo(docId);
        return this.success(ls);
    }

    @PostMapping("/create")
    @ApiOperation(value = "新增知识库",response= KnowledgeInfoPo.class)
    public AjaxResult createKnowlege(@RequestBody KnowledgeInfoPo kinfoPo){
        String rebakMsg = klinfoService.createKnowlege(kinfoPo);
        if(rebakMsg.equals("保存成功")){
            return this.success(rebakMsg);
        }else{
            return  this.error(rebakMsg);
        }

    }


    @PostMapping("/update")
    @ApiOperation(value = "保存知识库",response= KnowledgeInfoPo.class)
    public AjaxResult updateKnowlege(@RequestBody KnowledgeInfoPo kinfoPo){
        String rebakMsg = klinfoService.updateKnowlege(kinfoPo);
        if(rebakMsg.equals("保存成功")){
            return this.success(rebakMsg);
        }else{
            return  this.error(rebakMsg);
        }

    }

}
